package com.hnzq.cloud.sendassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hnzq.cloud.IO.AddSendOrderIO;
import com.hnzq.cloud.sendassembly.entity.FreSendOrderE;
import com.hnzq.cloud.sendassembly.mapper.FreSendOrderMapper;
import com.hnzq.cloud.sendassembly.service.FreSendOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnzq.cloud.util.ComUtil;
import com.hnzq.cloud.util.FreException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tiangle
 * @since 2022-02-07
 */
@Service
public class FreSendOrderServiceImpl extends ServiceImpl<FreSendOrderMapper, FreSendOrderE> implements FreSendOrderService {

    @Override
    public boolean addToSend(AddSendOrderIO addSendOrderIO) throws FreException {
        System.out.println("警方发");
        List<Integer> orderIds = addSendOrderIO.getOrderIds();
        QueryWrapper<FreSendOrderE> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("order_id",orderIds);
        List<FreSendOrderE> list = list(queryWrapper);
        System.out.println("列表："+list);
        if (list==null||list.size()>0){
            return false;
        }
        //调用orderAPI 查找orderIds是否存在

        List<FreSendOrderE> sendOrders = new ArrayList<>();
        System.out.println(11111);
        for (int i=0;i<orderIds.size();i++){
            sendOrders.add(FreSendOrderE.builder().sendStatus(0).sendId(addSendOrderIO.getSendId()).orderId(orderIds.get(i)).build());
            System.out.println(33+"  "+i);
        }
        System.out.println(22222);
        return saveOrUpdateBatch(sendOrders);


    }

    @Override
    public Long getSendByOrder(Integer orderId) {
        QueryWrapper<FreSendOrderE> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id",orderId);
        FreSendOrderE one = getOne(queryWrapper);
        return one.getSendId();
    }
}
